package kk.yiyi.safedesign.warming;

import android.app.Activity;
import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.content.res.AssetManager;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.HandlerThread;

import java.io.IOException;

public class WarmUtils {

    private static WarmUtils mInstance;
    private WarmUtils(){}
    public static WarmUtils getInstance(){
        if(mInstance==null){
            mInstance=new WarmUtils();
        }
        return mInstance;
    }

    public void startWarming(final Activity activity){
        AudioManager mAudioManager = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE);
        //最大音量
        int maxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
        mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, maxVolume, 0); //tempVolume:音量绝对值
        AssetManager assetManager;
        MediaPlayer player = null;
        player = new MediaPlayer();
        assetManager = activity.getResources().getAssets();
        try {
            AssetFileDescriptor fileDescriptor = assetManager.openFd("warm.mp3");
            player.setDataSource(fileDescriptor.getFileDescriptor(), fileDescriptor.getStartOffset(), fileDescriptor.getStartOffset());
            player.prepare();
            player.start();

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
